cmake_minimum_required(VERSION 3.8)
project(ego_planner_adapter)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rclcpp_lifecycle REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(nav_msgs REQUIRED)
find_package(sensor_msgs REQUIRED)
find_package(visualization_msgs REQUIRED)
find_package(tf2 REQUIRED)
find_package(tf2_ros REQUIRED)
find_package(tf2_geometry_msgs REQUIRED)
find_package(eigen3_cmake_module REQUIRED)
find_package(Eigen3 REQUIRED)

# Try to find ego-planner dependencies (they might not be built yet)
find_package(traj_utils QUIET)
find_package(quadrotor_msgs QUIET)

set(dependencies
  rclcpp
  rclcpp_lifecycle
  std_msgs
  geometry_msgs
  nav_msgs
  sensor_msgs
  visualization_msgs
  tf2
  tf2_ros
  tf2_geometry_msgs
  Eigen3
)

# Add ego-planner dependencies if found
if(traj_utils_FOUND)
  list(APPEND dependencies traj_utils)
endif()
if(quadrotor_msgs_FOUND)
  list(APPEND dependencies quadrotor_msgs)
endif()

# Include directories
include_directories(include)

# Trajectory Tracker Node
add_executable(trajectory_tracker_node
  src/trajectory_tracker_node.cpp
  src/trajectory_tracker.cpp
  src/bspline_interpolator.cpp
)

ament_target_dependencies(trajectory_tracker_node ${dependencies})

# Target Relay Node (for converting rviz goals to ego-planner format)
add_executable(target_relay_node
  src/target_relay_node.cpp
  src/target_relay.cpp
)

ament_target_dependencies(target_relay_node ${dependencies})

# Install targets
install(TARGETS
  trajectory_tracker_node
  target_relay_node
  DESTINATION lib/${PROJECT_NAME}
)

# Install include directory
install(DIRECTORY include/
  DESTINATION include/
)

# Install launch files
install(DIRECTORY launch/
  DESTINATION share/${PROJECT_NAME}/launch/
)

# Install config files
install(DIRECTORY config/
  DESTINATION share/${PROJECT_NAME}/config/
)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()